# Maintainer: Massimiliano Torromeo <massimiliano.torromeo@gmail.com>

pkgname=nginx-mod-naxsi
pkgver=1.3
pkgrel=8
_modname=naxsi
pkgdesc='Nginx Anti XSS & SQL Injection'
arch=('loong64' 'x86_64')
depends=('nginx')
makedepends=('nginx-src')
url="https://github.com/nbs-system/naxsi"
license=('GPL3')
backup=('etc/nginx/naxsi_core.rules')
source=(https://github.com/nbs-system/$_modname/archive/$pkgver/$_modname-$pkgver.tar.gz
        pcre2.patch)
validpgpkeys=(B0F4253373F8F6F510D42178520A9993A1C052F8) # Maxim Dounin <mdounin@mdounin.ru>
sha256sums=('439c8677372d2597b4360bbcc10bc86490de1fc75695b193ad5df154a214d628'
            'd02832f606488f72a3e1dfd1381f157dffcbed44e67563b4c0086d2d806425ef')

prepare() {
	mkdir -p "$srcdir"/build
	cd "$srcdir"/build

	ln -sf /usr/src/nginx/auto
	ln -sf /usr/src/nginx/src

	# pcre2 patch
	cd "$srcdir"/$_modname-$pkgver
	patch -Np1 < ../pcre2.patch
}

build() {
	cd "$srcdir"/build
	/usr/src/nginx/configure --with-compat --add-dynamic-module=../$_modname-$pkgver/naxsi_src
	make modules
}

package() {
	cd "$srcdir"/build/objs
	for mod in *.so; do
		install -Dm755 "$mod" "$pkgdir/usr/lib/nginx/modules/$mod"
	done

	cd "$srcdir"/$_modname-$pkgver
	install -Dm644 naxsi_config/naxsi_core.rules "$pkgdir"/etc/nginx/naxsi_core.rules
}
